package client2;

import java.rmi.RemoteException;

import client2.LoadInfoStub.BookRoom;
import client2.LoadInfoStub.BookRoomResponse;
import client2.LoadInfoStub.CancelBooking;
import client2.LoadInfoStub.DateType;
import client2.LoadInfoStub.GetAvailableRooms;
import client2.LoadInfoStub.GetAvailableRoomsResponse;
import client2.LoadInfoStub.RoomInfo;
import client2.LoadInfoStub.StayPeriodType;

public class Webserviceclient2 {
	/*public static void main(String [] args) throws RemoteException{
		System.out.println("HEy");

		LoadInfoStub stub = new LoadInfoStub();

		DateType checkin = new DateType();
		DateType checkout = new DateType();
				
		checkin.setDate(15);
		checkin.setMonth(11);
		checkin.setYear(2012);

		checkout.setDate(30);
		checkout.setMonth(11);
		checkout.setYear(2012);

		StayPeriodType period = new StayPeriodType();		
		period.setCheckin(checkin);
		period.setCheckout(checkout);
		
		BookRoom bookroom = new BookRoom();
		
		bookroom.setAmount(2);
		bookroom.setPeriod(period);
		bookroom.setType("Whatead");
		
		BookRoomResponse responsebooks = stub.bookRoom(bookroom);
		System.out.println("Book Rooms: " + responsebooks.get_return());
	}*/
	
	public static void main(String[] args) throws RemoteException {

		LoadInfoStub stub = new LoadInfoStub();

		DateType checkin = new DateType();
		DateType checkout = new DateType();
		StayPeriodType period = new StayPeriodType();
		checkin.setDate(15);
		checkin.setMonth(11);
		checkin.setYear(2012);

		checkout.setDate(30);
		checkout.setMonth(11);
		checkout.setYear(2012);

		period.setCheckin(checkin);
		period.setCheckout(checkout);
		//OK now i loaded some test data for the getRooms function

		//pass them in the getRooms function
		getRooms(stub, period);
		
		checkin.setDate(15);
		checkin.setMonth(11);
		checkin.setYear(2012);

		checkout.setDate(30);
		checkout.setMonth(11);
		checkout.setYear(2012);

		period.setCheckin(checkin);
		period.setCheckout(checkout);
		//OK now i loaded some test data for the BookRooms function

		bookRooms(stub,"standard",5,period);
		
		cancelBooking(stub, "e1d6590e-20c8-4a80-8a95-649db39f2173");
	}

	public static void getRooms(LoadInfoStub stub, StayPeriodType period) throws RemoteException{
			
		GetAvailableRooms getrooms = new GetAvailableRooms();

		getrooms.setPeriod(period);
		GetAvailableRoomsResponse responserooms = stub.getAvailableRooms(getrooms);
		
		RoomInfo[] roomsInfo = responserooms.get_return();
		
		for (RoomInfo room : roomsInfo){
			if (room != null) {
				System.out.println("Available Room: " + room.getRate());
			}
		}

	}
	
	public static void bookRooms(LoadInfoStub stub, String type, int amount, StayPeriodType period) throws RemoteException{
		
		BookRoom bookrooms = new BookRoom();
		
		bookrooms.setType(type);
		bookrooms.setAmount(amount);
		bookrooms.setPeriod(period);
		
		BookRoomResponse responsebooks = stub.bookRoom(bookrooms);
		System.out.println("Book Rooms: " + responsebooks.get_return());
	}

	public static void cancelBooking(LoadInfoStub stub, String id) throws RemoteException{
		
		CancelBooking cancel = new CancelBooking();
		stub.cancelBooking(cancel);
		System.out.println("Booking with id: " + id + "is canceled");
	}
}
